// Simple test script to debug WASM loading
async function testWasmLoading() {
  try {
    console.log('Attempting to load WASM module directly from path...');
    
    // Try to load WASM module using the absolute URL path
    const wasmPath = '../../pkg/kameo-wasm_bg.wasm';
    const wasmResponse = await fetch(wasmPath);
    
    if (!wasmResponse.ok) {
      throw new Error(`Failed to fetch WASM module: ${wasmResponse.status} ${wasmResponse.statusText}`);
    }
    
    console.log('WASM file fetched, attempting to compile...');
    const wasmBytes = await wasmResponse.arrayBuffer();
    const wasmModule = await WebAssembly.compile(wasmBytes);
    console.log('WASM module compiled successfully');
    
    // Now try to import the JS module
    console.log('Attempting to import JS wrapper module...');
    const jsModule = await import('../../pkg/kameo-wasm.js');
    console.log('JS module imported, available exports:', Object.keys(jsModule));
    
    // Try to initialize the WASM module
    if (typeof jsModule.default === 'function') {
      console.log('Found init function, initializing...');
      const wasmInstance = await jsModule.default();
      console.log('WASM module initialized successfully:', wasmInstance);
    }
    
    document.getElementById('result').textContent = 'WASM test completed successfully!';
  } catch (error) {
    console.error('Error in WASM test:', error);
    if (error instanceof Error) {
      console.error('Error message:', error.message);
      console.error('Error stack:', error.stack);
    }
    document.getElementById('result').textContent = `Error: ${error.message}`;
  }
}

// Create UI elements
document.addEventListener('DOMContentLoaded', () => {
  const button = document.createElement('button');
  button.textContent = 'Test WASM Loading';
  button.addEventListener('click', testWasmLoading);
  document.body.appendChild(button);
  
  const result = document.createElement('div');
  result.id = 'result';
  result.style.marginTop = '20px';
  result.style.padding = '10px';
  result.style.border = '1px solid #ccc';
  result.textContent = 'Click the button to test WASM loading';
  document.body.appendChild(result);
}); 